<template>
	<view class="store">

		<view class="store-top-box" v-if="merchantId > 0">
			<view class="store-top-left">
				<image class="store-logo" src="../../static/img/logo.png" mode=""></image>
			</view>
			<view class="store-top-right">
				<view class="store-title"> {{title}} </view>
				<!-- <view class="store-NO"> No: {{no}} </view> -->
			</view>
		</view>
		
		
		<uni-swiper-dot v-if="false && adv.length > 0" :info="adv" :dotsStyles="dotsStyles" :current="current" field="content" :mode="mode">
			<swiper class="swiper-box" @change="change" interval="3000" duration="500" circular="true" autoplay="true">
				<swiper-item v-for="(item ,index) in adv" :key="index">
					<view class="swiper-item">
						<image :src="item.cover" mode="widthFix" @click="jump(item.jump_type, item.jump_link)"></image>
					</view>
				</swiper-item>
			</swiper>
		</uni-swiper-dot>
		<view class="nav">
			<view class="item" @click="jump('product_classify', 'storeType=2')">
				<image src="http://app.chinasrv.com/attachment/xcx/icon/icon4.png" mode="aspectFill"></image>
				<text style="font-size: 40rpx;">商品分类</text>
			</view>
			<view class="item" @click="jump('product_brand', 'storeType=2')">
				<image src="http://app.chinasrv.com/attachment/xcx/icon/icon5.png" mode="aspectFill"></image>
				<text style="font-size: 40rpx;">商品品牌</text>
			</view>
		</view>
		<view class="nav1">
			<image src="../../static/img/tab_alcohol.png" lazy-load="true" mode="aspectFill"
				@click="jump('product_brand', 'mainType=1&storeType=2')"></image>
			<image src="../../static/img/tab_tea.png" lazy-load="true" mode="aspectFill"
				@click="jump('product_brand', 'mainType=2&storeType=2')"></image>
		</view>



		<view v-if="bagList.itemList.length > 0" class="salePackage-box">
			<view class="salePackage-title"> {{bagList.title}} </view>
			<view class="salePackage1" v-if="bagList.itemList.length == 1"
				@click="jump('bag_view',bagList.itemList[0].id)">
				<view class="salePackage1-good">
					<image class="salePackage1-img" :src="bagList.itemList[0].picture"></image>
					<view v-if="bagList.itemList[0].is_buyer == 1" class="good-buyP">
						{{bagList.itemList[0].buyer_text}}
					</view>
					<view class="salePackage1-disc">
						<view class="salePackage1-title"> {{bagList.itemList[0].name}} </view>
						<view class="salePackage1-pic"> ￥{{bagList.itemList[0].price}} </view>
					</view>
				</view>
			</view>
			<view class="salePackage2" v-if="bagList.itemList.length == 2">
				<view class="salePackage2-good" v-for="(item, index) in bagList.itemList" :key="index"
					@click="jump('bag_view',item.id)">
					<image class="salePackage2-img" :src="item.picture"></image>
					<view v-if="item.is_buyer == 1" class="good-buyP">
						{{item.buyer_text}}
					</view>
					<view class="salePackage2-disc">
						<view class="salePackage2-title"> {{item.name}} </view>
						<view class="salePackage2-pic"> ￥{{item.price}} </view>
					</view>
				</view>
			</view>
			<view class="salePackage3" v-if="bagList.itemList.length >= 3">
				<scroll-view class="scroll" scroll-with-animation scroll-x show-scrollbar>
					<view class="salePackage3-good" v-for="(item, index) in bagList.itemList" :key="index"
						@click="jump('bag_view',item.id)"
						:style="index+1 == bagList.itemList.length ? 'margin-right: 0;': ''">
						<image class="salePackage3-img" :src="item.picture"></image>
						<view v-if="item.is_buyer == 1" class="good-buyP">
							{{item.buyer_text}}
						</view>
						<view class="salePackage3-disc">
							<view class="salePackage3-title"> {{item.name}} </view>
							<view class="salePackage3-pic"> ￥{{item.price}} </view>
						</view>
					</view>
				</scroll-view>
			</view>
		</view>

		<view class="content1" v-for="(tabItem, k) in tabList" :key="k">
			<view class="title">
				{{tabItem.title}}
			</view>
			<view class="list">
				<view class="list_item" v-for="(item,index) in tabItem.productList" :key="index" @click="jump('product_view', 'id='+item.id+'&storeType='+storeType)">
					<image :src="item.picture" mode=""></image>
					<view class="item_text">
						<text class="state" style="background:rgba(235, 89, 56, 1);">{{item.reductionName}}{{item.isReduction == 1 ? '满减' : ''}}</text>
						{{item.name}}
					</view>
					<view class="item_text1">
						<view>￥{{item.minPrice + (item.minPrice != item.maxPrice ? ' - ' + item.maxPrice : '')}}</view>
					</view>
				</view>
			</view>
		</view>
		<movable-view class="xf" direction="all" @click="jump('cart')">
			<image src="http://hdsq.aoorange.cn/attachment/xcx/icon/car.png" mode="scaleToFill"></image>
			<text>{{cartNum}}</text>
		</movable-view>

	</view>
</template>

<script>
	var _self;
	import serve from '../../static/request.js';
	import storage from '../../static/appkey.js';
	import common from '../../static/jump.js';
	export default {
		data() {
			return {
				messageNum: 0,
				merchantId: 0,
				storeType: 2,
				title: '超圳商城',
				adv: [],
				tabList: {},
				cartNum: 0,
				current: 0,
				mode: 'round',
				isShowTea: true,
				isBatch: 0,
				dotsStyles: {
					backgroundColor: 'rgba(255,255,255,0.3)',
					selectedBackgroundColor: '#FFC600',
					selectedBorder: '1px rgba(255,198,0,1) solid',
					border: '1px rgba(255,255,255,0.3) solid',
					selectedBorder: '1px rgba(255,198,0,1) solid'
				}, //轮播图样式配置

				selfId: 0,
				bagList: {},
				no: ''
			}
		},
		methods: {
			change(e) {
				_self.current = e.detail.current;
			},
			getAdvList() {
				serve.request({
					url: '/marketing/merchant/adv-list',
					data: {
						appkey: uni.getStorageSync('appkey'),
						merchantId: _self.merchantId,
					}
				}).then(res => {
					_self.adv = res.data;
				});
			},
			getIndex() {
				serve.request({
					url: '/store/index/index',
					data: {
						appkey: uni.getStorageSync('appkey'),
						'access-token': uni.getStorageSync('access-token'),
						merchantId: _self.merchantId,
						storeType: _self.storeType,
					},
					v: '/v2',
				}).then(res => {
					_self.title = res.data.title;
					_self.no = res.data.no;
					_self.merchantId = res.data.merchantId;
					wx.setNavigationBarTitle({
						title: _self.title + _self.no,
					});
					
					_self.tabList = res.data.tabList;
					_self.bagList = res.data.bagItem
				});
			},
			getCartNum() {
				if (uni.getStorageSync('access-token') == '') {
					return;
				}
				serve.request({
					url: '/store/cart/get-num',
					data: {
						appkey: uni.getStorageSync('appkey'),
						'access-token': uni.getStorageSync('access-token'),
						storeType: _self.storeType,
					},
					v: '/v2',
				}).then(res => {
					_self.cartNum = res.data.num;
				});
			},
			jump(jump_type, jump_link) {
				common.jump(jump_type, jump_link);
			}
		},
		async onLoad(options) {
			_self = this;
			await _self.$defaultLogin();
			_self.merchantId = options.merchantId || 0;
			_self.storeType = options.storeType || 2;
			let paramStr = uni.getStorageSync('param_filter');
            if(paramStr) {
                let paramList = paramStr.split('&');
                paramList.forEach((v,k) => {
                	var paramArr = v.split('=');
                	if(paramArr.length == 2) {
                		_self.$set(_self, paramArr[0], paramArr[1]);
                	}
                });
            }
			_self.getIndex();
			_self.getCartNum();
		},
		onPullDownRefresh() {
			_self.getIndex();
			_self.getCartNum();
		}
	}
</script>

<style lang="scss" scoped>
	@media only screen and (device-width: 375px) and (device-height: 812px) and (-webkit-device-pixel-ratio: 3) {
		.store {
			padding-bottom: 164rpx !important;
		}
	}

	.store {
		width: 100%;
		padding-bottom: 140rpx;

		.store-top-box{
			padding: 30rpx;
			background: linear-gradient(250deg,#fd6a6a, #963700);
			
			margin-bottom: 17rpx;
			display: flex;
			justify-content: start;
			align-items: center;
			border-bottom: 16rpx #FBFBFD solid;
			.store-top-left{
				display: flex;
				justify-content: center;
				align-items: center;
				.store-logo{
					width: 120rpx;
					height: 120rpx;
				}
			}
			.store-top-right{
				margin-left: 40rpx;
				font-size: 36rpx;
				color: #FFF;
				line-height: 1.5;
				.store-title{
					font-size: 60rpx;
				}
				.store-NO{
					font-size: 30rpx;
					color: #FFF;
				}
			}
		}


		.xf {
			position: fixed;
			left: 630rpx;
			top: 70%;
			width: 90rpx;
			height: 90rpx;

			image {
				width: 100%;
				height: 100%;
			}

			text {
				position: absolute;
				width: 30rpx;
				height: 30rpx;
				right: 5rpx;
				line-height: 30rpx;
				text-align: center;
				border-radius: 50%;
				font-size: 18rpx;
				background: red;
				color: #FFFFFF;
			}
		}

		.top {
			position: fixed;
			// top: 88rpx;
			z-index: 10;
			width: 100%;
			height: 100rpx;
			width: 100%;
			background: #FBCA3F;
			box-sizing: border-box;
			padding: 0rpx 30rpx;
			display: flex;
			justify-content: center;
			align-items: center;

			.top_img {
				position: absolute;
				top: 32rpx;
				right: 30rpx;
				width: 40rpx;
				height: 40rpx;

				image {
					width: 100%;
					height: 100%;
				}

				.dot {
					width: 14rpx;
					height: 14rpx;
					background: rgba(235, 89, 56, 1);
					border-radius: 50%;
					position: absolute;
					right: 0;
					top: 0;
				}
			}
		}

		.swiper-box {
			width: 100%;
			height: 700rpx;
			// margin-top: 100rpx;

			image {
				width: 100%;
				height: 420rpx;
			}
		}

		.content {
			margin: 0rpx 30rpx;
			padding: 34rpx 0rpx;
			display: flex;
			font-size: 20rpx;
			justify-content: space-between;
			border-bottom: 1rpx rgba(57, 72, 107, 0.1) solid;
			align-items: center;

			.content_text {
				display: flex;
				align-items: center;

				.content_num {
					font-size: 40rpx;
					color: #FFC600;
					margin-left: 20rpx;
				}
			}
		}

		.content1 {
			box-sizing: border-box;
			width: 100%;
			padding: 48rpx 30rpx 18rpx;
			border-top: 16rpx #FBFBFD solid;
			border-bottom: 16rpx #FBFBFD solid;

			.title {
				position: relative;
				// width: 130rpx;
				font-size: 40rpx;
				// text-align: center;
				padding-left: 20rpx;
				height: 24rpx;
				line-height: 24rpx;
			}

			.title::before {
				content: '';
				position: absolute;
				left: 0;
				top: 0;
				width: 6rpx;
				height: 24rpx;
				background: rgba(255, 198, 0, 1);
				border-radius: 2rpx;
			}

			.list {
				display: flex;
				justify-content: space-between;
				flex-wrap: wrap;
				padding: 30rpx 0rpx 0rpx;

				.list_item {
					width: 330rpx;
					padding-bottom: 30rpx;

					image {
						width: 330rpx;
						height: 340rpx;
						border-radius: 3%;
					}

					.state {
						padding: 5rpx 8rpx;
						text-align: center;
						color: #FFFFFF;
						font-size: 32rpx;
						border-radius: 2rpx;
						margin-right: 10rpx;
					}

					.item_text {
						margin-top: 30rpx;
						font-size: 32rpx;
						font-weight: bold;
						text-overflow: -o-ellipsis-lastline;
						overflow: hidden;
						text-overflow: ellipsis;
						display: -webkit-box;
						-webkit-line-clamp: 2;
						-webkit-box-orient: vertical;

					}

					.item_text1 {
						view:nth-child(1) {
							color: #FFC600;
							font-size: 32rpx;
						}

						view:nth-child(2) {
							color: #CBCBCB;
							font-size: 24rpx;
							text-decoration: line-through;
							margin-left: 8rpx;
						}
					}
				}
			}
		}


		.nav {
			box-sizing: border-box;
			width: 100%;
			display: flex;
			justify-content: space-between;
			padding: 40rpx 107rpx;
			border-bottom: 16rpx #FBFBFD solid;

			.item {
				display: flex;
				align-items: center;
				font-size: 28rpx;

				image {
					width: 36rpx;
					height: 36rpx;
					margin-right: 12rpx;
				}
			}
		}

		.nav1 {
			box-sizing: border-box;
			padding: 40rpx 30rpx;
			display: flex;
			justify-content: space-between;
			border-bottom: 16rpx #FBFBFD solid;

			image {
				width: 330rpx;
				height: 130rpx;
				border-radius: 10rpx;
			}
		}

		.info {
			padding-top: 78rpx;
			width: 100%;
			text-align: center;
			font-size: 24rpx;
			font-weight: 400;
			color: rgba(57, 72, 107, 0.5);

			text:first-child {
				margin-right: 20rpx;
			}

			.contact {
				background: white;
				height: 130rpx;
				width: 200rpx;
				box-sizing: border-box;
				display: inline;
				font-size: 24rpx;
				font-weight: 400;
				color: rgba(57, 72, 107, 0.5);
			}
		}
	}



	.salePackage-box {
		width: 690rpx;
		position: relative;
		padding: 48rpx 30rpx 18rpx;
		border-top: 16rpx #FBFBFD solid;
		border-bottom: 16rpx #FBFBFD solid;
	}

	.salePackage-title {
		position: relative;
		width: 500rpx;
		font-size: 40rpx;
		text-align: left;
		height: 24rpx;
		line-height: 24rpx;
		padding-left: 30rpx;

		&::before {
			content: '';
			position: absolute;
			left: 0;
			top: 0;
			width: 6rpx;
			height: 24rpx;
			background: #ffc600;
			border-radius: 2rpx;
			background-image: initial;
			background-position-x: initial;
			background-position-y: initial;
			background-size: initial;
			background-repeat-x: initial;
			background-repeat-y: initial;
			background-attachment: initial;
			background-origin: initial;
			background-clip: initial;
			background-color: rgb(255, 198, 0);
			border-top-left-radius: 1px;
			border-top-right-radius: 1px;
			border-bottom-right-radius: 1px;
			border-bottom-left-radius: 1px;
		}
	}



	.salePackage1 {
		margin-top: 30rpx;
		position: relative;
	}

	.salePackage1-good {
		width: 100%;
		display: flex;
		position: relative;
	}

	.salePackage1-img {
		width: 200rpx;
		height: 200rpx;
		border-radius: 3%;
	}

	.salePackage1-disc {
		margin-left: 30rpx;
		display: flex;
		flex-direction: column;
		align-items: flex-start;
		justify-content: space-evenly;
		width: 460rpx;
	}

	.salePackage1-title {
		overflow: hidden;
		word-break: break-all;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		font-size: 32rpx;
		font-weight: bold;
	}

	.salePackage1-pic {
		color: #FFC600;
		font-size: 32rpx;
	}


	.salePackage2 {
		margin-top: 30rpx;
		display: flex;
		-webkit-box-pack: justify;
		justify-content: space-between;
		flex-wrap: wrap;
		position: relative;
	}

	.salePackage2-good {
		width: 330rpx;
		padding-bottom: 30rpx;
		position: relative;
	}

	.salePackage2-img {
		width: 330rpx;
		height: 340rpx;
		border-radius: 3%;
	}

	.salePackage2-disc {}

	.salePackage2-title {
		margin-top: 30rpx;
		font-size: 32rpx;
		font-weight: bold;
		text-overflow: -o-ellipsis-lastline;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
	}

	.salePackage2-pic {
		color: #FFC600;
		font-size: 32rpx;
	}

	.salePackage3 {
		margin-top: 30rpx;
		position: relative;
	}

	.scroll {
		width: 690rpx;
		display: flex;
		flex-direction: row;
		white-space: nowrap;
	}

	.salePackage3-good {
		display: inline-block;
		width: 210rpx;
		margin-right: 30rpx;
		position: relative;
	}

	.salePackage3-img {
		width: 210rpx;
		height: 210rpx;
		border-radius: 3%;
	}

	.salePackage3-disc {}

	.salePackage3-title {
		overflow: hidden;
		word-break: break-all;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		font-size: 28rpx;
		font-weight: bold;
		white-space: break-spaces;
		height: 80rpx;
	}

	.salePackage3-pic {
		color: #FFC600;
		font-size: 28rpx;
	}
	.good-buyP{
		position: absolute;
		right: 12rpx;
		color: #f76363;
		font-size: 28rpx;
		font-weight: bold;
		top: 270rpx;
		transform: rotate(-45deg);
		border-bottom: 2rpx solid;
		padding-bottom: 10rpx;
	}
</style>
